import https from "../https/Https.js";
var regionCtrl = {
	data:[],
}
//加载行政区域
regionCtrl.getRegion = function(callBack=null)
{
	let that = this;
	https.districts({},back);
	function back(data)
	{
		if(!data)return;
		if(data.status == 1)
		{
			if(!data.data)return;
			that.data = data.data;
			if(callBack)
			{
				callBack.apply(this,[data.data]);
			}
		}
	}
}

/****获取省份，城市，区名称****/
regionCtrl.getProCityArea = function(pCode,cCode,aCode)
{
	let arr = [];
	let len = this.data.length;
	for(let i = 0; i<len; i++)
	{
		let temp = this.data[i];
		if(temp.code == pCode)
		{
			arr.push(temp.name);
			let len1 = temp.cityList.length;
			for(let j = 0; j < len1; j++)
			{
				let temp1 = temp.cityList[j];
				if(temp1.code == cCode)
				{
					arr.push(temp1.name);
					let len2 = temp1.cityList.length;
					for(let k = 0; k < len2; k++)
					{
						let temp2 =  temp1.cityList[k];
						if(temp2.code == aCode)
						{
							arr.push(temp2.name);
							break;
						}
					}
					break;
				}
			}
			break;
		}
	}
	return arr;
}

regionCtrl.getCity = function(code)
{
	
}

regionCtrl.getArea = function(code)
{
	
}


export default regionCtrl;